package com.firegod.servicebase.entity;

import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;
import java.util.Set;

@Entity
@DiscriminatorValue("2")
@Getter
@NoArgsConstructor
public class Student extends User {

    @ManyToMany
    @Setter
    @JoinTable(name = "student_course",
            joinColumns = @JoinColumn(name = "student_id"),
            inverseJoinColumns = @JoinColumn(name = "course_id"),
            uniqueConstraints = {@UniqueConstraint(columnNames = {"course_id", "student_id"})})
    private Set<Course> courseList;

    public Student(String userId) {
        this.userId = userId;
    }

    public Student(String userId, String name) {
        this.userId = userId;
        this.name = name;
    }

    public JSONObject show() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("userId", userId);
        jsonObject.put("name", name);
        jsonObject.put("email", email);
        jsonObject.put("mobile", mobile);
        return jsonObject;
    }
}
